home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 May: Tool Chest / Developer CD Series May 1996 (Tool Chest) (Apple Computer) (1996).iso / Tool Chest / Development Tools & Languages / Dylan Related / Mindy / Mindy 1.2 - portable sources / comp / print.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-03-15  |  21.2 KB  |  761 lines  |  [TEXT/ttxt]

  1. /**********************************************************************\
  2. *
  3. *  Copyright (c) 1994  Carnegie Mellon University
  4. *  All rights reserved.
  5. *  
  6. *  Use and copying of this software and preparation of derivative
  7. *  works based on this software are permitted, including commercial
  8. *  use, provided that the following conditions are observed:
  9. *  
  10. *  1. This copyright notice must be retained in full on any copies
  11. *     and on appropriate parts of any derivative works.
  12. *  2. Documentation (paper or online) accompanying any system that
  13. *     incorporates this software, or any part of it, must acknowledge
  14. *     the contribution of the Gwydion Project at Carnegie Mellon
  15. *     University.
  16. *  
  17. *  This software is made available "as is".  Neither the authors nor
  18. *  Carnegie Mellon University make any warranty about the software,
  19. *  its performance, or its conformity to any specification.
  20. *  
  21. *  Bug reports, questions, comments, and suggestions should be sent by
  22. *  E-mail to the Internet address "gwydion-bugs@cs.cmu.edu".
  23. *
  24. ***********************************************************************
  25. *
  26. * $Header: print.c,v 1.14 94/10/05 20:55:53 nkramer Exp $
  27. *
  28. * This file prints out parts of the parse tree in a human readable
  29. * format for debugging purposes.
  30. *
  31. \**********************************************************************/
  32.  
  33. #include "../compat/std-c.h"
  34.  
  35. #include "mindycomp.h"
  36. #include "src.h"
  37. #include "sym.h"
  38. #include "literal.h"
  39. #include "print.h"
  40. #include "lose.h"
  41.  
  42. static char spaces[] = "                                                            ";
  43. #define indent(x) (spaces+sizeof(spaces)-1-((x)%60))
  44.  
  45.  
  46.  
  47. /* Property lists. */
  48.  
  49. static void print_plist(struct plist *plist, int depth)
  50. {
  51.     struct property *prop;
  52.  
  53.     if (plist == NULL)
  54.     return;
  55.  
  56.     printf("%sproperty list\n", indent(depth));
  57.     for (prop = plist->head; prop != NULL; prop = prop->next) {
  58.     printf("%s%s:\n", indent(depth+1), prop->keyword->name);
  59.     print_expr(prop->expr, depth+2);
  60.     }
  61.     printf("%send property list\n", indent(depth));
  62. }
  63.  
  64.  
  65. /* Literal printing. */
  66.  
  67. static void print_symbol_literal(struct symbol_literal *l, int depth)
  68. {
  69.     printf("%ssymbol %s\n", indent(depth), l->symbol->name);
  70. }
  71.  
  72. static void print_integer_literal(struct integer_literal *l, int depth)
  73. {
  74.     printf("%sinteger %ld\n", indent(depth), l->value);
  75. }
  76.  
  77. static void print_single_float_literal(struct single_float_literal *l,
  78.                        int depth)
  79. {
  80.     printf("%ssingle float %g\n", indent(depth), l->value);
  81. }
  82.  
  83. static void print_double_float_literal(struct double_float_literal *l,
  84.                        int depth)
  85. {
  86.     printf("%sdouble float %g\n", indent(depth), l->value);
  87. }
  88.  
  89. static void print_extended_float_literal(struct extended_float_literal *l,
  90.                      int depth)
  91. {
  92.     printf("%sextended float %g\n", indent(depth), (double)l->value);
  93. }
  94.  
  95. static void print_char(int c, int quote)
  96. {
  97.     switch (c) {
  98.       case '"':
  99.       case '\'':
  100.     if (c == quote)
  101.         printf("\\%c", c);
  102.     else
  103.         putchar(c);
  104.     break;
  105.       case '\b': printf("\\b");    break;
  106.       case '\f': printf("\\f");    break;
  107.       case '\n': printf("\\n");    break;
  108.       case '\r': printf("\\r");    break;
  109.       case '\t': printf("\\t");    break;
  110.       default:
  111.     if (' ' <= c && c <= '~')
  112.         putchar(c);
  113.     else
  114.         printf("\\%03o", c);
  115.     break;
  116.     }
  117. }
  118.  
  119. static void print_character_literal(struct character_literal *l, int depth)
  120. {
  121.     printf("%scharacter '", indent(depth));
  122.     print_char(l->value, '\'');
  123.     printf("'\n");
  124. }
  125.  
  126. static void print_string_literal(struct string_literal *l, int depth)
  127. {
  128.     char *ptr;
  129.     int i;
  130.  
  131.     printf("%sstring \"", indent(depth));
  132.     ptr = (char *)l->chars;
  133.     for (i = 0; i < l->length; i++)
  134.     print_char(*ptr++, '"');
  135.     printf("\"\n");
  136. }
  137.  
  138. static void print_list_literal(struct list_literal *l, int depth)
  139. {
  140.     struct literal *piece;
  141.  
  142.     printf("%slist\n", indent(depth));
  143.     for (piece = l->first; piece != NULL; piece = piece->next)
  144.     print_literal(piece, depth+1);
  145.     if (l->tail) {
  146.     printf("%sdot\n", indent(depth));
  147.     print_literal(l->tail, depth+1);
  148.     }
  149.     printf("%send list\n", indent(depth));
  150. }
  151.  
  152. static void print_vector_literal(struct vector_literal *l, int depth)
  153. {
  154.     struct literal *piece;
  155.  
  156.     printf("%svector\n", indent(depth));
  157.     for (piece = l->first; piece != NULL; piece = piece->next)
  158.     print_literal(piece, depth+1);
  159.     printf("%send vector\n", indent(depth));
  160. }
  161.  
  162. static void print_true_literal(struct literal *l, int depth)
  163. {
  164.     printf("%s#t\n", indent(depth));
  165. }
  166.  
  167. static void print_false_literal(struct literal *l, int depth)
  168. {
  169.     printf("%s#f\n", indent(depth));
  170. }
  171.  
  172. static void print_unbound_literal(struct literal *l, int depth)
  173. {
  174.     printf("%s#unbound\n", indent(depth));
  175. }
  176.  
  177. static void (*LiteralPrinters[(int)literal_Kinds])() = {
  178.     print_symbol_literal, print_integer_literal,
  179.     print_single_float_literal, print_double_float_literal,
  180.     print_extended_float_literal, print_character_literal,
  181.     print_string_literal, print_list_literal, print_vector_literal,
  182.     print_true_literal, print_false_literal, print_unbound_literal
  183. };
  184.  
  185. void print_literal(struct literal *literal, int depth)
  186. {
  187.     (LiteralPrinters[(int)literal->kind])(literal, depth);
  188. }
  189.  
  190.  
  191. /* Utility printers. */
  192.  
  193. static void print_param(struct param *param, int depth, char *kind, int index)
  194. {
  195.     if (param->type_temp)
  196.     printf("%s%s %d: %s :: %s\n", indent(depth), kind, index,
  197.            param->id->symbol->name, param->type_temp->name);
  198.     else {
  199.     printf("%s%s %d: %s\n", indent(depth), kind, index,
  200.            param->id->symbol->name);
  201.     if (param->type) {
  202.         printf("%styped\n", indent(depth+1));
  203.         print_expr(param->type, depth+2);
  204.     }
  205.     }
  206. }
  207.  
  208. static void print_param_list(struct param_list *list, int depth)
  209. {
  210.     struct param *p;
  211.     struct keyword_param *k;
  212.     int i;
  213.  
  214.     for (p = list->required_params, i = 0; p != NULL; p = p->next, i++)
  215.     print_param(p, depth, "param", i);
  216.     if (list->next_param)
  217.     printf("%s#next %s\n", indent(depth), list->next_param->symbol->name);
  218.     if (list->rest_param)
  219.     printf("%s#rest %s\n", indent(depth), list->rest_param->symbol->name);
  220.     if (list->allow_keys) {
  221.     printf("%s#key\n", indent(depth));
  222.     for (k = list->keyword_params; k != NULL; k = k->next) {
  223.         if (k->id->symbol != k->keyword)
  224.         printf("%s%s: %s", indent(depth+1), k->keyword->name,
  225.                k->id->symbol->name);
  226.         else
  227.         printf("%s%s:", indent(depth+1), k->keyword->name);
  228.         if (k->type_temp)
  229.         printf(" :: %s\n", k->type_temp->name);
  230.         else if (k->type) {
  231.         printf("\n%styped\n", indent(depth+2));
  232.         print_expr(k->type, depth+3);
  233.         }
  234.         else
  235.         putchar('\n');
  236.         if (k->def) {
  237.         printf("%sdefault\n", indent(depth+2));
  238.         print_expr(k->def, depth+3);
  239.         }
  240.     }
  241.     if (list->all_keys)
  242.         printf("%s#all-keys\n", indent(depth));
  243.     }
  244. }
  245.  
  246. static void print_bindings(struct bindings *bindings, int depth)
  247. {
  248.     printf("%sbind\n", indent(depth));
  249.     print_param_list(bindings->params, depth+1);
  250.     if (bindings->expr) {
  251.     printf("%sto\n", indent(depth));
  252.     print_expr(bindings->expr, depth+1);
  253.     }
  254. }
  255.  
  256. static void print_return_type_list(struct return_type_list *l, int depth)
  257. {
  258.     int i;
  259.     struct return_type *r;
  260.  
  261.     if (l == NULL)
  262.     return;
  263.  
  264.     printf("%sreturns\n", indent(depth));
  265.     for (i = 0, r = l->req_types; r != NULL; i++, r = r->next)
  266.     if (r->temp)
  267.         printf("%sresult %d: %s\n", indent(depth+1), i, r->temp->name);
  268.     else if (r->type) {
  269.         printf("%sresult %d:\n", indent(depth+1), i);
  270.         print_expr(r->type, depth+2);
  271.     }
  272.     else
  273.         printf("%sresult %d.\n", indent(depth+1), i);
  274.     if (l->rest_temp)
  275.     printf("%s#rest %s\n", indent(depth+1), l->rest_temp->name);
  276.     else if (l->rest_type) {
  277.     printf("%s#rest\n", indent(depth+1));
  278.     print_expr(l->rest_type, depth+2);
  279.     }
  280.     else if (l->restp)
  281.     printf("%s#rest foo :: <object>\n", indent(depth+1));
  282.     printf("%send returns\n", indent(depth));
  283. }
  284.  
  285. static char *debug_name_string(struct literal *literal)
  286. {
  287.     switch (literal->kind) {
  288.       case literal_SYMBOL:
  289.     return (char *)((struct symbol_literal *)literal)->symbol->name;
  290.       case literal_STRING:
  291.     return (char *)((struct string_literal *)literal)->chars;
  292.       default:
  293.     return "with strange debug name";
  294.     }
  295. }
  296.  
  297. static void print_method(struct method *method, int depth)
  298. {
  299.     fputs(indent(depth), stdout);
  300.     if (method->top_level)
  301.     fputs("top level ", stdout);
  302.     if (method->debug_name)
  303.     printf("method %s\n", debug_name_string(method->debug_name));
  304.     else if (method->name)
  305.     printf("method %s\n", method->name->symbol->name);
  306.     else
  307.     fputs("anonymous method\n", stdout);
  308.  
  309.     print_param_list(method->params, depth+1);
  310.     if (method->specializers) {
  311.     printf("%sspecializers\n", indent(depth));
  312.     print_expr(method->specializers, depth+1);
  313.     }
  314.     print_return_type_list(method->rettypes, depth);
  315.     printf("%sbody\n", indent(depth));
  316.     print_body(method->body, depth+1);
  317.  
  318.     printf("%send ", indent(depth));
  319.     if (method->top_level)
  320.     fputs("top level ", stdout);
  321.     if (method->debug_name)
  322.     printf("method %s\n", debug_name_string(method->debug_name));
  323.     else if (method->name)
  324.     printf("method %s\n", method->name->symbol->name);
  325.     else
  326.     fputs("anonymous method\n", stdout);
  327. }
  328.  
  329. static void print_exception_clause(struct exception_clause *clause, int depth)
  330. {
  331.     printf("%sexception\n%stype\n", indent(depth), indent(depth+1));
  332.     print_expr(clause->type, depth+2);
  333.     if (clause->condition)
  334.     printf("%scondition %s\n", indent(depth+1),
  335.            clause->condition->symbol->name);
  336.     print_plist(clause->plist, depth+1);
  337.     printf("%shandler\n", indent(depth+1));
  338.     print_body(clause->body, depth+2);
  339. }
  340.  
  341. static void print_condition_body(struct condition_body *body, int depth)
  342. {
  343.     struct condition *c;
  344.  
  345.     while (body != NULL) {
  346.     c = body->clause->conditions;
  347.     if (c) {
  348.         printf("%swhen\n", indent(depth));
  349.         while (1) {
  350.         print_expr(c->cond, depth+1);
  351.         c = c->next;
  352.         if (c == NULL)
  353.             break;
  354.         printf("%sor\n", indent(depth));
  355.         }
  356.         printf("%s=>\n", indent(depth));
  357.     }
  358.     else
  359.         printf("%sotherwise\n", indent(depth));
  360.     print_body(body->clause->body, depth+1);
  361.     body = body->next;
  362.     }
  363. }
  364.  
  365.  
  366. /* Expr printing stuff. */
  367.  
  368. static void print_varref_expr(struct varref_expr *e, int depth)
  369. {
  370.     printf("%svarref %s\n", indent(depth), e->var->symbol->name);
  371. }
  372.  
  373. static void print_literal_expr(struct literal_expr *e, int depth)
  374. {
  375.     print_literal(e->lit, depth);
  376. }
  377.  
  378. static void print_call_expr(struct call_expr *e, int depth)
  379. {
  380.     int i;
  381.     struct argument *arg;
  382.  
  383.     printf("%scall\n%sfunction:\n", indent(depth), indent(depth+1));
  384.     print_expr(e->func, depth+2);
  385.     for (i = 0, arg = e->args; arg != NULL; i++, arg = arg->next) {
  386.     printf("%sargument %d\n", indent(depth+1), i);
  387.     print_expr(arg->expr, depth+2);
  388.     }
  389.     printf("%send call\n", indent(depth));
  390. }
  391.  
  392. static void print_method_expr(struct method_expr *e, int depth)
  393. {
  394.     print_method(e->method, depth);
  395. }
  396.  
  397. static void print_dot_expr(struct dot_expr *e, int depth)
  398. {
  399.     printf("%sdot operator\n%sargument\n", indent(depth), indent(depth+1));
  400.     print_expr(e->arg, depth+2);
  401.     printf("%sfunction\n", indent(depth+1));
  402.     print_expr(e->func, depth+2);
  403.     printf("%send dot operator\n", indent(depth));
  404. }
  405.  
  406. static void print_body_expr(struct body_expr *e, int depth)
  407. {
  408.     printf("%sbegin\n", indent(depth));
  409.     print_body(e->body, depth+1);
  410.     printf("%send\n", indent(depth));
  411. }
  412.  
  413. static void print_block_expr(struct block_expr *e, int depth)
  414. {
  415.     struct exception_clause *clause;
  416.  
  417.     if (e->exit_fun)
  418.     printf("%sblock (%s)\n", indent(depth), e->exit_fun->symbol->name);
  419.     else
  420.     printf("%sblock <no exit function>\n", indent(depth));
  421.     print_body(e->body, depth+1);
  422.     if (e->inner)
  423.     for (clause = e->inner; clause != NULL; clause = clause->next)
  424.         print_exception_clause(clause, depth);
  425.     if (e->cleanup) {
  426.     printf("%scleanup\n", indent(depth));
  427.     print_body(e->cleanup, depth+1);
  428.     }
  429.     if (e->outer)
  430.     for (clause = e->outer; clause != NULL; clause = clause->next)
  431.         print_exception_clause(clause, depth);
  432.     printf("%send block\n", indent(depth));
  433. }
  434.  
  435. static void print_case_expr(struct case_expr *e, int depth)
  436. {
  437.     print_condition_body(e->body, depth);
  438.     printf("%send case\n", indent(depth));
  439. }
  440.  
  441. static void print_if_expr(struct if_expr *e, int depth)
  442. {
  443.     printf("%sif\n", indent(depth));
  444.     print_expr(e->cond, depth+1);
  445.     printf("%sconsequent\n", indent(depth));
  446.     print_body(e->consequent, depth+1);
  447.     printf("%salternate\n", indent(depth));
  448.     print_body(e->alternate, depth+1);
  449.     printf("%send if\n", indent(depth));
  450. }
  451.  
  452. static void print_for_expr(struct for_expr *e, int depth)
  453. {
  454.     struct for_clause *clause;
  455.     int i;
  456.  
  457.     printf("%sfor\n", indent(depth));
  458.     for (clause=e->clauses, i=0; clause != NULL; clause=clause->next, i++) {
  459.     print_param_list(clause->vars, depth+1);
  460.     switch (clause->kind) {
  461.       case for_EQUAL_THEN:
  462.         {
  463.         struct equal_then_for_clause *c
  464.             = (struct equal_then_for_clause *)clause;
  465.         printf("%sequal\n", indent(depth+2));
  466.         print_expr(c->equal, depth+3);
  467.         printf("%sthen\n", indent(depth+2));
  468.         print_expr(c->then, depth+3);
  469.         }
  470.         break;
  471.       case for_IN:
  472.         {
  473.         struct in_for_clause *c = (struct in_for_clause *)clause;
  474.         printf("%sin\n", indent(depth+2));
  475.         print_expr(c->collection, depth+3);
  476.         }
  477.         break;
  478.       case for_FROM:
  479.         {
  480.         struct from_for_clause *c = (struct from_for_clause *)clause;
  481.         printf("%sfrom\n", indent(depth+2));
  482.         print_expr(c->from, depth+3);
  483.         if (c->to) {
  484.             static char *to_kinds[] = {"to", "above", "below"};
  485.             printf("%s%s\n", indent(depth+2),
  486.                to_kinds[(int)c->to_kind]);
  487.             print_expr(c->to, depth+3);
  488.         }
  489.         if (c->by) {
  490.             printf("%sby\n", indent(depth+2));
  491.             print_expr(c->by, depth+3);
  492.         }
  493.         }
  494.         break;
  495.       default:
  496.         lose("Bogus for clause kind.");
  497.     }
  498.     }
  499.     if (e->until) {
  500.     printf("%suntil\n", indent(depth));
  501.     print_expr(e->until, depth+1);
  502.     }
  503.     printf("%sdo\n", indent(depth));
  504.     print_body(e->body, depth+1);
  505.     if (e->finally) {
  506.     printf("%sfinally\n", indent(depth));
  507.     print_body(e->finally, depth+1);
  508.     }
  509.     printf("%send for\n", indent(depth));
  510. }
  511.  
  512. static void print_select_expr(struct select_expr *e, int depth)
  513. {
  514.     printf("%sselect\n", indent(depth));
  515.     print_expr(e->expr, depth+1);
  516.     if (e->by) {
  517.     printf("%sby\n", indent(depth));
  518.     print_expr(e->by, depth+1);
  519.     }
  520.     print_condition_body(e->body, depth);
  521.     printf("%send select\n", indent(depth));
  522. }
  523.  
  524. static void print_varset_expr(struct varset_expr *e, int depth)
  525. {
  526.     printf("%svarset %s\n", indent(depth), e->var->symbol->name);
  527.     print_expr(e->value, depth+1);
  528.     printf("%send varset\n", indent(depth));
  529. }
  530.  
  531. static void print_binop_series_expr(struct binop_series_expr *e, int depth)
  532. {
  533.     struct binop *b;
  534.  
  535.     printf("%sbinop series\n", indent(depth));
  536.     print_expr(e->first_operand, depth+1);
  537.     for (b = e->first_binop; b != NULL; b = b->next) {
  538.     printf("%sbinop %s\n", indent(depth), b->op->symbol->name);
  539.     print_expr(b->operand, depth+1);
  540.     }
  541.     printf("%send binop series\n", indent(depth));
  542. }
  543.  
  544. static void print_loop_expr(struct loop_expr *e, int depth)
  545. {
  546.     printf("%sloop\n", indent(depth));
  547.     print_body(e->body, depth+1);
  548.     printf("%send loop\n", indent(depth));
  549. }
  550.  
  551. static void print_repeat_expr(struct repeat_expr *e, int depth)
  552. {
  553.     printf("%srepeat\n", indent(depth));
  554. }
  555.  
  556. static void print_error_expr(struct expr *e, int depth)
  557. {
  558.     printf("%serror expr\n", indent(depth));
  559. }
  560.  
  561. static void (*ExprPrinters[(int)expr_Kinds])() = {
  562.     print_varref_expr, print_literal_expr, print_call_expr,
  563.     print_method_expr, print_dot_expr, print_body_expr, print_block_expr,
  564.     print_case_expr, print_if_expr, print_for_expr, print_select_expr,
  565.     print_varset_expr, print_binop_series_expr, print_loop_expr,
  566.     print_repeat_expr, print_error_expr
  567. };
  568.  
  569. void print_expr(struct expr *e, int depth)
  570. {
  571.     (*ExprPrinters[(int)e->kind])(e, depth);
  572. }
  573.  
  574.  
  575. /* Constituent printing stuff. */
  576.  
  577. static void
  578.     print_defconst_constituent(struct defconst_constituent *c, int depth)
  579. {
  580.     printf("%sdefine constant\n", indent(depth));
  581.     print_bindings(c->bindings, depth+1);
  582.     if (c->tlf) {
  583.     printf("%sinitializer\n", indent(depth));
  584.     print_method(c->tlf, depth+1);
  585.     }
  586.     printf("%send define constant\n", indent(depth));
  587. }
  588.  
  589. static void print_defvar_constituent(struct defvar_constituent *c, int depth)
  590. {
  591.     printf("%sdefine variable\n", indent(depth));
  592.     print_bindings(c->bindings, depth+1);
  593.     if (c->tlf) {
  594.     printf("%sinitializer\n", indent(depth));
  595.     print_method(c->tlf, depth+1);
  596.     }
  597.     printf("%send define variable\n", indent(depth));
  598. }
  599.  
  600. static void
  601.     print_defmethod_constituent(struct defmethod_constituent *c, int depth)
  602. {
  603.     printf("%sdefine method\n", indent(depth));
  604.     if (c->tlf)
  605.     print_method(c->tlf, depth+1);
  606.     else
  607.     print_method(c->method, depth+1);
  608.     printf("%send define method\n", indent(depth));
  609. }
  610.  
  611. static void
  612.     print_defgeneric_constituent(struct defgeneric_constituent *c, int depth)
  613. {
  614.     printf("%sdefine generic\n", indent(depth));
  615.     printf("%sname: %s\n", indent(depth+1), c->name->symbol->name);
  616.     print_param_list(c->params, depth+1);
  617.     print_return_type_list(c->rettypes, depth+1);
  618.     print_plist(c->plist, depth+1);
  619.     if (c->tlf) {
  620.     printf("%ssignature generator\n", indent(depth));
  621.     print_method(c->tlf, depth+1);
  622.     }
  623.     printf("%send define generic\n", indent(depth));
  624. }
  625.  
  626. static void
  627.     print_defclass_constituent(struct defclass_constituent *c, int depth)
  628. {
  629.     static char *alloc[] = {"instance", "class", "subclass",
  630.                 "constant", "virtual"};
  631.     struct superclass *super;
  632.     struct slot_spec *slot;
  633.     struct initarg_spec *initarg;
  634.     struct inherited_spec *inherited;
  635.  
  636.     printf("%sdefine class\n", indent(depth));
  637.     printf("%sname: %s\n", indent(depth+1), c->name->symbol->name);
  638.     if (c->tlf1) {
  639.     printf("%sphase 1:\n", indent(depth+1));
  640.     print_method(c->tlf1, depth+2);
  641.     printf("%sphase 2:\n", indent(depth+1));
  642.     print_method(c->tlf2, depth+2);
  643.     }
  644.     else {
  645.     printf("%ssupers:\n", indent(depth+1));
  646.     for (super = c->supers; super != NULL; super = super->next)
  647.         print_expr(super->expr, depth+2);
  648.     printf("%sslots:\n", indent(depth+1));
  649.     for (slot = c->slots; slot != NULL; slot = slot->next) {
  650.         printf("%s%s slot, %s allocation\n", indent(depth+2),
  651.            slot->name ? (char*)slot->name->symbol->name : "anonymous",
  652.            alloc[(int)slot->alloc]);
  653.         if (slot->type) {
  654.         printf("%stype:\n", indent(depth+2));
  655.         print_expr(slot->type, depth+3);
  656.         }
  657.         print_plist(slot->plist, depth+2);
  658.     }
  659.         printf("%sinitialization arguments:\n", indent(depth+1));
  660.         for (initarg = c->initargs; initarg != NULL;
  661.          initarg = initarg->next) {
  662.             printf("%s%s%s initarg\n", indent(depth+2),
  663.                    initarg->keyword->name,
  664.                    initarg->required ? " required " : "");
  665.             print_plist(initarg->plist, depth+2);
  666.         }
  667.     printf("%sinherited slots:\n", indent(depth+1));
  668.     for (inherited = c->inheriteds; inherited != NULL;
  669.          inherited = inherited->next) {
  670.         printf("%s%s inherited slot\n", indent(depth+2),
  671.            inherited->name->symbol->name);
  672.         print_plist(inherited->plist, depth+2);
  673.     }
  674.     }
  675.     printf("%send define class\n", indent(depth));
  676. }
  677.  
  678. static void print_expr_constituent(struct expr_constituent *c, int depth)
  679. {
  680.     print_expr(c->expr, depth);
  681. }
  682.  
  683. static void print_local_constituent(struct local_constituent *c, int depth)
  684. {
  685.     struct method *method;
  686.  
  687.     printf("%slocal\n", indent(depth));
  688.     for (method = c->methods; method != NULL; method = method->next_local)
  689.     print_method(method, depth+1);
  690.     printf("%sbody\n", indent(depth));
  691.     print_body(c->body, depth+1);
  692.     printf("%send local\n", indent(depth));
  693. }
  694.  
  695. static void print_handler_constituent(struct handler_constituent *c, int depth)
  696. {
  697.     printf("%shandler\n", indent(depth));
  698.     if (c->type) {
  699.     printf("%stype:\n", indent(depth+1));
  700.     print_expr(c->type, depth+2);
  701.     printf("%sfunction:\n", indent(depth+1));
  702.     print_expr(c->func, depth+2);
  703.     print_plist(c->plist, depth+1);
  704.     }
  705.     printf("%sbody\n", indent(depth));
  706.     print_body(c->body, depth+1);
  707.     printf("%send handler\n", indent(depth));
  708. }
  709.  
  710. static void print_let_constituent(struct let_constituent *c, int depth)
  711. {
  712.     print_bindings(c->bindings, depth);
  713.     printf("%sbody\n", indent(depth));
  714.     print_body(c->body, depth+1);
  715.     printf("%send bind\n", indent(depth));
  716. }
  717.  
  718. static void print_tlf_constituent(struct tlf_constituent *c, int depth)
  719. {
  720.     printf("%stop level form\n", indent(depth));
  721.     print_method(c->form, depth+1);
  722.     printf("%send top level form\n", indent(depth));
  723. }
  724.  
  725. static void print_error_constituent(struct constituent *c, int depth)
  726. {
  727.     printf("%serror constituent\n", indent(depth));
  728. }
  729.  
  730. static void print_defmodule_constituent(struct constituent *c, int depth)
  731. {
  732.     printf("%sdefmodule constituent\n", indent(depth));
  733. }
  734.  
  735. static void print_deflibrary_constituent(struct constituent *c, int depth)
  736. {
  737.     printf("%sdeflibrary constituent\n", indent(depth));
  738. }
  739.  
  740. static void (*ConstituentPrinters[(int)constituent_Kinds])() = {
  741.     print_defconst_constituent, print_defvar_constituent,
  742.     print_defmethod_constituent, print_defgeneric_constituent,
  743.     print_defclass_constituent, print_expr_constituent,
  744.     print_local_constituent, print_handler_constituent,
  745.     print_let_constituent, print_tlf_constituent, print_error_constituent,
  746.     print_defmodule_constituent, print_deflibrary_constituent
  747. };
  748.  
  749. void print_constituent(struct constituent *c, int depth)
  750. {
  751.     (ConstituentPrinters[(int)c->kind])(c, depth);
  752. }
  753.  
  754. void print_body(struct body *body, int depth)
  755. {
  756.     struct constituent *c;
  757.  
  758.     for (c = body->head; c != NULL; c = c->next)
  759.     print_constituent(c, depth);
  760. }
  761.